package master

import (
	"encoding/json"
	"io/ioutil"
)

type Config struct {
	ApiPort int `json:"ApiPort"`
	ApiReadTimeout int `json:"ApiReadTimeout"`
	ApiWriteTimeout int `json:"ApiWriteTimeout"`
	ApiEndpoints []string `json:"ApiEndpoints"`
	ApiEtcdTimeout int `json:"ApiEtcdTimeout"`
	EtcdUserName string `json:"EtcdUserName"`
	EtcdPassword string `json:"EtcdPassword"`
	WebRootDir string `json:"WebRootDir"`
	MongoUri string `json:"MongoUri"`
	MongoTimeout int `json:"MongoTimeout"`
}

var (
	G_Config *Config
)

// 初始化配置
func InitConfig(filename string) (err error) {
	var (
		content []byte
	)
	content,err = ioutil.ReadFile(filename)
	if err != nil {
		return err
	}
	G_Config = &Config{}
	err =json.Unmarshal(content,G_Config)
	if err != nil {
		return err
	}
	return nil
}